import { makeAutoObservable } from 'mobx';
import { inject, injectable } from 'inversify';
import { RoleItemModel } from '../models/role.detail.model.ts';
import { GetRoleDetailUseCase } from '../usecase/getRoleDetailUseCase.ts';
import { ROLE_TYPE } from '../config/enum.ts';
import { RolePermission } from '../models/interface.ts';

@injectable()
export class RoleItemViewModel {
  get loading(): boolean {
    return this.roleItemModel.loading;
  }

  get id(): string {
    return this.roleItemModel.role._id;
  }

  get name(): string {
    return this.roleItemModel.role.name;
  }

  get description(): string {
    return this.roleItemModel.role.description;
  }

  get type(): ROLE_TYPE {
    return this.roleItemModel.role.type;
  }

  get isActive(): boolean {
    return this.roleItemModel.role.isActive;
  }

  get permissions(): RolePermission[] {
    return this.roleItemModel.role.permissions;
  }
  get createdAt(): string {
    return this.roleItemModel.role.createdAt;
  }

  get updatedAt(): string {
    return this.roleItemModel.role.updatedAt;
  }

  constructor(
    @inject(RoleItemModel)
    private roleItemModel: RoleItemModel,
    @inject(GetRoleDetailUseCase)
    private getRoleDetailUseCase: GetRoleDetailUseCase,
  ) {
    makeAutoObservable(this);
  }

  async initialize(id: string) {
    await this.getRoleDetailUseCase.execute(id);
  }

  dispose() {
    this.roleItemModel.dispose();
  }
}
